package com.tangmu.rabbits.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.tangmu.rabbits.R;
import com.tangmu.rabbits.ui.activity.home.NineElementActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/4/25.
 */

public class HomeActivitiesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private LayoutInflater inflater;
    private List<Integer> datas = new ArrayList<>();

    public HomeActivitiesAdapter(Context mContext, List<Integer> datas) {
        this.mContext = mContext;
        this.datas = datas;
        inflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ActivitiesViewHolder(inflater.inflate(R.layout.rv_item_home_activity_, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        final ActivitiesViewHolder viewHolder = (ActivitiesViewHolder) holder;
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickLisener != null)
                    itemClickLisener.onItemClick(v, position);
            }
        });
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }

    class ActivitiesViewHolder extends RecyclerView.ViewHolder {

        public ActivitiesViewHolder(View itemView) {
            super(itemView);
        }
    }

    private OnItemClickLisener itemClickLisener;

    public void setItemClickLisener(OnItemClickLisener itemClickLisener) {
        this.itemClickLisener = itemClickLisener;
    }

    public interface OnItemClickLisener {
        void onItemClick(View view, int position);
    }

}
